# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=portaudio
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=19_20140130
pkgrel=2
pkgdesc="A free, cross-platform, open source, audio I/O library (mingw-w64)"
arch=('any')
url="http://www.portaudio.com"
license=("custom")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" "${MINGW_PACKAGE_PREFIX}-pkg-config")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
options=(!libtool strip !makeflags staticlibs)
source=("http://www.portaudio.com/archives/pa_stable_v${pkgver}.tgz"
        mingw-w64-fix.patch
        mingw-w64-cmake-allow-cxx.patch)
sha256sums=('8fe024a5f0681e112c6979808f684c3516061cc51d3acc0b726af98fc96c8d57'
            'b328834eb1e0b9f93dda2ae9494742509e83ac8610299296e536335350864e48'
            'a909152b1e620335b4cc996f082c7799130cd9b00caf6c61a3e82005933c2b77')

prepare() {
  cd ${srcdir}/${_realname}
  patch -p2 -i ${srcdir}/mingw-w64-fix.patch
  patch -p2 -i ${srcdir}/mingw-w64-cmake-allow-cxx.patch

  autoconf
}

build() {
  export lt_cv_deplibs_check_method='pass_all'
  [[ -d "build-${MINGW_CHOST}" ]] && rm -rf "build-${MINGW_CHOST}"
  mkdir -p "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"
  ../${_realname}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --enable-shared \
    --enable-cxx \
    --with-dxdir=${MINGW_PREFIX}/${MINGW_CHOST} \
    --with-winapi=wmme,directx,wdmks
    #wasapi,

  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR="${pkgdir}" install
}
